local juyi = fk.CreateSkill {
    name = "ym1__juyi",
    dynamic_desc = function (self, player, lang)
        if type(player:getMark("ym1__juyi_phase")) == "table" then
            return "ym1__juyi2"
        else
            return "ym1__juyi"
        end
    end,
}
juyi:addEffect(fk.EventPhaseEnd,{
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) then
            return table.contains({Player.Judge,Player.Draw,Player.Play,Player.Discard},player.phase) and (type(player:getMark("ym1__juyi_phase")) ~= "table" or not table.contains(player:getMark("ym1__juyi_phase"), player.phase))
        end
    end,
    on_cost = function (self, event, target, player, data)
        if type(player:getMark("ym1__juyi_phase")) ~= "table" then
            local arr = type(player:getMark("ym1__juyi_phase")) == "table" and player:getMark("ym1__juyi_phase") or {}
            return player.room:askToSkillInvoke(player,{
                skill_name = juyi.name,
                prompt = "#ym1__juyi-invoke:::"..Fk:translate(Util.PhaseStrMapper(player.phase))..":"..(#arr+1),
            })
        else
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local arr = type(player:getMark("ym1__juyi_phase")) == "table" and player:getMark("ym1__juyi_phase") or {}
        local turns = {"turn_start","phase_start","phase_judge","phase_draw","phase_play","phase_discard","phase_finish","turn_finish"}
        local str = "<font color=#cacaca><s>"
        table.insert(arr,player.phase)
        table.sort(arr)
        for _, v in ipairs(arr) do
            str = str..Fk:translate("ym1__"..turns[v])
        end
        room:notifySkillInvoked(player,juyi.name,"drawcard")
        player:broadcastSkillInvoke(juyi.name,math.random(1,2))
        room:setPlayerMark(player,"ym1__juyi_phase",arr)
        room:setPlayerMark(player,"@ym1__juyi",str.."</s></font>")
        room:drawCards(player,#arr,juyi.name)
    end,
})
juyi:addEffect(fk.EventPhaseChanging,{
    frequency = Skill.Compulsory,
    mute = true,
    can_trigger = function(self, event, target, player, data)
        if target == player and not player:insideExtraTurn() and type(player:getMark("ym1__juyi_phase")) == "table" and data.phase > 2 and data.phase < 7 then
            return table.contains(player:getMark("ym1__juyi_phase"), data.phase)
        end
    end,
    on_cost = function (self, event, target, player, data)
        return true
    end,
    on_use = function (self, event, target, player, data)
        if player:usedSkillTimes(juyi.name, Player.HistoryTurn) == 1 then
            player:broadcastSkillInvoke("ym1__juyi",3)
        end
        data.skipped = true
    end,
})
Fk:loadTranslationTable{
    ["ym1__juyi"] = "举义",
    [":ym1__juyi"] = "主要阶段结束时，你可以删除“可以”和额定回合的该阶段，然后摸X张牌。（X为你已删除阶段数+1）",
    [":ym1__juyi2"] = "主要阶段结束时，你删除额定回合的该阶段，然后摸X张牌。（X为你已删除阶段数+1）",
    ["#ym1__juyi-invoke"] = "举义：是否删除额定回合的%arg，然后摸%arg2张牌",
    ["@ym1__juyi"] = "<font color=#cacaca>举义</font>",

    ["$ym1__juyi1"] = "司马氏篡权，我当替天伐之！",
    ["$ym1__juyi2"] = "定当夷司马氏三族！",
    ["$ym1__juyi3"] = "咳……咳咳……",
}
return juyi